package main

import (
	"os"
	"text/template"
)

const tpl = `Hello, {{.Name}}! You like {{len .Like}}.`

type Person struct {
	Name string
	Age  int
	Like []string
}

func main() {
	t := template.New("test")
	t, err := t.Parse(tpl)
	if err != nil {
		panic(err)
	}

	p := Person{Name: "Tom", Age: 18, Like: []string{"语文", "数学", "英语"}}
	data := map[string]interface{}{
		"Name": p.Name,
		"Age":  p.Age,
		"Like": p.Like,
	}

	err = t.Execute(os.Stdout, data)
	if err != nil {
		panic(err)
	}

}
